package demo0529;

import java.util.HashMap;
import java.util.Map;

public class TestMap {
    private Map<Integer, Emp> employeeMap = new HashMap<>();

    public void addEmployee(Emp employee) {
        employeeMap.put(employee.getId(), employee);
        System.out.println("员工添加成功: " + employee);
    }

    public Emp getEmployee(int id) {
        Emp employee = employeeMap.get(id);
        if (employee == null) {
            System.out.println("未找到员工ID: " + id);
        }
        return employee;
    }

    public void deleteEmployee(int id) {
        Emp removed = employeeMap.remove(id);
        if (removed != null) {
            System.out.println("员工删除成功: " + removed);
        } else {
            System.out.println("未找到员工ID: " + id);
        }
    }

    public void updateEmployee(int id, String newName) {
        Emp employee = employeeMap.get(id);
        if (employee != null) {
            employee.setName(newName);
            System.out.println("员工信息更新成功: " + employee);
        } else {
            System.out.println("未找到员工ID: " + id);
        }
    }
    public void displayAllEmployees() {
        if (employeeMap.isEmpty()) {
            System.out.println("员工列表为空");
        } else {
            System.out.println("所有员工信息:");
            for (Emp emp : employeeMap.values()) {
                System.out.println(emp);
            }
        }
    }
    public void deleteAllEmployees() {
        employeeMap.clear();
        System.out.println("已删除所有员工信息");
    }
}
